﻿//======================================================================
//
//        Copyright : Zhengzhou Strawberry Computer Technology Co.,LTD.
//        All rights reserved
//        
//        Application:NFinal MVC framework
//        Filename :Extension.cs
//        Description :项目扩展类
//
//        created by Lucas at  2015-6-30`
//     
//        WebSite:http://www.nfinal.com
//
//======================================================================
using System;
using System.Collections.Generic;
using System.Web;

namespace ${namespace}
{
    public static class Extension
    {
        public static void Error(this NFinal.BaseAction action, string msg, string url, int second)
        {
            Web.Default.Common.Public.ErrorAction errorAction = new Web.Default.Common.Public.ErrorAction(action._tw);
            errorAction.Error(msg, url, second);
        }
        public static void Success(this NFinal.BaseAction action, string msg, string url, int second)
        {
            Web.Default.Common.Public.SuccessAction successAction = new Web.Default.Common.Public.SuccessAction(action._tw);
            successAction.Success(msg, url, second);
        }
		public static bool IsNullOrWhiteSpace(this string str)
        {
            return (str == null || str.Trim() == string.Empty);
        }
		public static void WriteJson<T>(this NFinal.DB.NList<T> strs,System.IO.TextWriter tw)
        {
            if (strs == null)
            {
                tw.Write("null");
            }
            else
            {
                tw.Write("[");
                bool isFirst = true;
                foreach (NFinal.DB.JsonInterface str in strs)
                {
                    if (!isFirst)
                    {
                        tw.Write(",");
                    }
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    str.WriteJson(tw);
                }
                tw.Write("]");
            }
        }
        public static string ToJson<T>(this NFinal.DB.NList<T> str)
        {
            System.IO.StringWriter tw = new System.IO.StringWriter();
            str.WriteJson(tw);
            string result = tw.ToString();
            tw.Close();
            return result;
        }
    }
}